const rightGroup = require("../entities/rightGroup");
const { assignProporties, getTextBox, getButton, getSelect } = require("../Common");

//systemManage/rightGroupEdit 500-599
const dataActionTypes = {
    //获取实体数据
    getEntityData: 500,
    //保存实体数据
    saveEntityData: 501
}
const { name, primaryKey } = rightGroup;
const entity = {
    name, primaryKey
}
module.exports = {
    name: "rightGroupEdit",
    type: "View",
    eventActions: getEventActions(),
    properties: assignProporties({ name: "rightGroupEdit" }, [getEditView()])
}

function getEditView() {
    return {
        name: "rightGroupEdit2",
        type: "RowsColsView",
        entity: entity,
        isForm: true,
        loadActionName: "getEntityData",
        isClear: true,
        className: 'divView3',
        saveEntityDataActionType: dataActionTypes.saveEntityData,
        getEntityDataActionType: dataActionTypes.getEntityData,
        properties: assignProporties(rightGroup, getProperties())
    }
}

function getButtonProperties() {
    return [{
        name: "leftSpace1",
        type: "WhiteSpace",
        className: "ant-col ant-col-8 ant-form-item-label"
    },
    { ...getButton("saveEntityData", "保存", "primary"), eventActionName: "saveEntityData", icon: 'save', style: { width: 84 } },
    { ...getButton("backToList", "返回", ""), eventActionName: "backToList", icon: 'left', style: { marginLeft: 10 } }]
}

function getProperties() {
    return [
        getTextBox2("Name", "名称", 1, 1, "", "请输入名称", 50, false),
        getEditSelect("DataRight", "数据权限", rightGroup.dataRightDataSource, 2, 1, '', 0),
        getEditSelect("OperationRight", "操作权限", rightGroup.operationRightDataSource, 3, 1, '', 0),
        getTextArea("Remark", "备注", 4, 1),
        getTree(),
        getButtonView()
    ]
}

function getTree() {
    return {
        name: 'MenuList',
        type: 'Tree',
        label: '菜单',
        x: 5,
        y: 1,
        rootValue: 0,
        isCheckBox: true,
        isFormItem: true,
        colSpan: 24,
        labelCol: 8,
        wrapperCol: 12,
        isNullable: false,
        nullTipMessage: '请选择菜单',
        isEdit: true,
        valueName: "value",
        textName: "text",
        parentValueName: 'parentValue',
        serviceDataSource: rightGroup.menuTreeNodesDataSource,
        isSelectValue: true,
        defaultExpandAll: true
    }
}

function getEditSelect(name, label, dataSource, x, y, placeHolder, defaultvalue) {
    return {
        ...getSelect(name, label, dataSource, x, y, defaultvalue),
        isFormItem: true,
        colSpan: 24,
        labelCol: 8,
        wrapperCol: 8,
        isNullable: false,
        placeHolder,
        isEdit: true
    }
}


function getTextArea(name, label, x, y, placeHolder) {
    return {
        ...getTextBox(name, label, "TextArea", x, y),
        isFormItem: true,
        isNullable: true,
        isEdit: true,
        colSpan: 24,
        rows: 3,
        placeHolder,
        labelCol: 8,
        wrapperCol: 8
    }
}


function getButtonView() {
    return {
        name: "buttonView",
        type: "View",
        className: "divCenterButton",
        isDiv: true,
        isFormItem: true,
        colSpan: 24,
        x: 7,
        y: 1,
        properties: assignProporties({ name: "rightGroupEdit" }, getButtonProperties())
    }
}

function getTextBox2(name, label, x, y, contorlType, placeHolder, maxLength, isNullable, isVisible, validateNames, validateTipMessage) {
    return {
        ...getTextBox(name, label, contorlType, x, y, placeHolder, maxLength || 50),
        validateNames, validateTipMessage,
        isFormItem: true,
        colSpan: 24,
        labelCol: 8,
        wrapperCol: 8,
        isNullable,
        isVisible,
        isEdit: true
    }
}

function getEventActions() {
    return [{
        name: "backToList",
        type: "page/toPage",
        propertyNames: [entity.primaryKey],
        pageUrl: '/rightGroupList.html?selectedRowKey=#{' + entity.primaryKey + '}'
    },
    {
        name: "saveEntityData",
        type: "entityEdit/saveEntityData",
        editView: "rightGroupEdit2",
        expandSetEntityData: 'expandSetEntityData'
    },
    {
        name: "getEntityData",
        type: "entityEdit/getEntityData",
        editView: "rightGroupEdit2",
        setGetEntityDataLoad: 'setGetEntityDataLoad'
    }]
}